package cn.raven.org.service.impl;

import cn.raven.basic.utils.PageList;
import cn.raven.org.domain.Department;
import cn.raven.org.mapper.DepartmentMapper;
import cn.raven.org.query.DepartmentQuery;
import cn.raven.org.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
/**

* @Description: 部门管理业务层
* @Author: king
* @Version: 1.0
* @Date:  2022/6/21 17:51
  */
@Service
//只读事务
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DepartmentServiceImpl implements IDepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;
    /**
    * @Title: findAll
    * @Description: 查询所有
    * @Author: king
    * @Version: 1.0
    * @Date:  2022/6/21 17:11
    * @Parameters: []
    * @Return java.util.List<cn.raven.org.domain.Department>
      */
    @Override
    public List<Department> findAll() {
        return departmentMapper.findAll();
    }

    /**
    * @Title: findOne
    * @Description: 根据id查询
    * @Author: king
    * @Version: 1.0
    * @Date:  2022/6/21 17:11
    * @Parameters: [id]
    * @Return cn.raven.org.domain.Department
      */
    @Override
    public Department findOne(Long id) {
        return departmentMapper.findOne(id);
    }
    
    /** 
    * @Title: add
    * @Description: 新增
    * @Author: Mr.She
    * @Version: 1.0
    * @Date:  2022/6/21 17:09  
    * @Parameters: [department]
    * @Return void
      */
    @Override
    @Transactional
    public void add(Department department) {
        departmentMapper.add(department);
    }

    /**
    * @Title: update
    * @Description: 更新
    * @Author: king
    * @Version: 1.0
    * @Date:  2022/6/21 17:43
    * @Parameters: [department]
    * @Return void
      */
    @Override
    @Transactional
    public void update(Department department) {
        departmentMapper.update(department);
    }
    /**
    * @Title: del
    * @Description: 删除
    * @Author: king
    * @Version: 1.0
    * @Date:  2022/6/21 17:51
    * @Parameters: [id]
    * @Return void
      */
    @Override
    @Transactional
    public void del(Long id) {
        departmentMapper.del(id);
    }
    /**
    * @Title: queryData
    * @Description: 分页+高级查询
    * @Author: king
    * @Version: 1.0
    * @Date:  2022/6/21 17:51
    * @Parameters: [departmentQuery]
    * @Return cn.raven.basic.utils.PageList<cn.raven.org.domain.Department>
      */
    @Override
    public PageList<Department> queryData(DepartmentQuery departmentQuery) {
        //查询总条数
        Integer total = departmentMapper.queryCount(departmentQuery);//
        //查询当前页数据
        List<Department> rows = departmentMapper.queryData(departmentQuery);
        return new PageList<Department>(total,rows);
    }
}
